package com.isunland.managesystem.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.DataStatus;

/**
 * Created by lenovo on 2016/11/25.
 */
public class ProblemBackStatusDialogFragment extends DialogFragment {
  protected static final String EXTRA_VALUE =
      "com.isunland.managesystem.ui.ProblemBackStatusDialogFragment.extra_value";
  private int[] choiceIds = new int[] {
      R.string.draft, R.string.handle, R.string.hasFinishplan, R.string.aborted, R.string.all
  };
  private String[] choiceStrings = new String[choiceIds.length];
  private String name = "";
  private String code = "";

  @Override public Dialog onCreateDialog(Bundle savedInstanceState) {

    return new AlertDialog.Builder(getActivity()).setSingleChoiceItems(getChoiceName(), 0,
        new DialogInterface.OnClickListener() {

          @Override public void onClick(DialogInterface dialog, int which) {
            switch (which) {
              //未开展
              case 0:
                code = DataStatus.NEW;
                break;
              //处理中
              case 1:
                code = DataStatus.SUBMIT;
                break;
              //已完成
              case 2:
                code = DataStatus.PUBLIS;
                break;
              //已验收
              case 3:
                code = DataStatus.ABORT;
                break;
              //全部
              case 4:
                code = "";
                break;

              default:
                break;
            }

            name = getChoiceName()[which];
            CustomerDialog content = new CustomerDialog(name, code);

            Intent i = new Intent();
            i.putExtra(EXTRA_VALUE, content);
            if (getTargetFragment() == null) {
              return;
            }
            getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, i);
            dialog.dismiss();
          }
        }).create();
  }

  private String[] getChoiceName() {
    for (int i = 0; i < choiceIds.length; i++) {

      choiceStrings[i] = getResources().getString(choiceIds[i]);
    }

    return choiceStrings;
  }
}
